package com.ctosb.classviewer.clazz.cp;

import com.ctosb.classviewer.ClassReader;
import com.ctosb.classviewer.clazz.ClassFile;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class CONSTANT_NameAndType_info extends Cp_info {

    private short name_index;
    private short descriptor_index;

    @Override
    protected void doParse(ClassReader classReader) {
        name_index = classReader.readShort();
        descriptor_index = classReader.readShort();
    }

    /**
     * 获取name值
     * @Author alan
     * @Date 2020/12/13 10:10 下午
     * @param classFile
     * @return
     */
    public String getNameValue(ClassFile classFile) {
        CONSTANT_Utf8_info cp_info = (CONSTANT_Utf8_info)classFile.getConstant_pool()[name_index];
        return cp_info.getValue();
    }

    /**
     * 获取descriptor值
     * @param classFile
     * @return
     */
    public String getDescriptorValue(ClassFile classFile) {
        CONSTANT_Utf8_info cp_info = (CONSTANT_Utf8_info)classFile.getConstant_pool()[descriptor_index];
        return cp_info.getValue();
    }
}
